<?php
error_reporting(0);
$user_c = $_GET[user];
$password_c = $_GET[password];
$password_c = md5(md5($password_c) . '0000'); //双重md5加密，密钥0000
$host = 'localhost';
$user = 'root';
$password = 'Xiangni365';
$database = 'login';
$con = mysqli_connect($host, $user, $password, $database);
$timestamp = date("YmdHis");
$cookie = base64_encode($user_c . $timestamp);
if (!$con) {
    die('Connection Failed!');
}
$user_check = mysqli_fetch_array(mysqli_query($con, "SELECT * FROM login_check WHERE user='$user_c'"));
if (sizeof($user_check) == 0) {
    echo ('0');
} else {
    $password_check = $user_check[2];
    if ($password_c == $password_check) {
        $status = $user_check[6];
        $status = intval($status);
        // echo($status);
        if ($status == 1) {
            $set_cookie = mysqli_query($con, "UPDATE login_check SET current_cookie='$cookie' WHERE user='$user_c'");
            if (!$set_cookie) {
                echo ('CoFai');
            } else {
                echo ($cookie);
            }

        } else {
            echo ("1");
        }
    } else {
        echo ("0");
    }
}
